﻿$G.versioning = {
	version: 110,
	versionHistory: [0, 100, 110],

	compareVersion: function (userObject) {
		if ($G.versioning.version > userObject.version) {
			$G.versioning.upgrade(userObject);
		}
	},

	upgrade: function (userObject) {
		var startUpgradeIndex = $G.versioning.versionHistory.indexOf(userObject.version);
		if (startUpgradeIndex == -1) {
			$G.errorAndExit('Version conflict');
		}
		for (var i = startUpgradeIndex; i < $G.versioning.versionHistory.length - 1; i++) {
			$G.versioning.upgradeToNext(userObject, i);
		}
		userObject.version = $G.versioning.version;
		$G.localStorage('gollieuser', userObject);
	},

	upgradeToNext: function (userObject, fromIndex) {
		var fromVersion = $G.versioning.versionHistory[fromIndex];
		var toVersion = $G.versioning.versionHistory[fromIndex + 1];
		if (toVersion == 110) {
			userObject.environment = 'prod';
		}
	}
}